package com.wang.tool.idem;

import com.wang.tool.idem.aop.EnableIdem;
import com.wang.tool.idem.core.DynamicIdemConfigCenter;
import com.wang.tool.idem.core.IdemConfig;
import com.wang.tool.util.CommonUtil;

public class IdemConfigCenter {

    public static final IdemConfig DEF_OPEN = new IdemConfig();

    static {
        DEF_OPEN.setOpen(true);
    }

    /**
     * @see EnableIdem#defIdemTtl()
     */
    private static int defIdemTtl;


    /**
     * @see EnableIdem#defLockWaitTime()
     */
    private static int defLockWaitTime;

    /**
     * @see EnableIdem#defLockSecond()
     */
    private static int defLockSecond;


    /**
     * @see EnableIdem#dynamicConfigCenter()
     */
    private static DynamicIdemConfigCenter dynamicConfigCenter;


    public static IdemConfig getIdemConfig(String namespace){
        if (CommonUtil.isBlank(namespace)) {
            throw new IllegalArgumentException("namespace can not be null");
        }
        IdemConfig idemConfig = dynamicConfigCenter.getIdemConfig(namespace);
        return idemConfig == null ? DEF_OPEN : idemConfig;
    }


    public static int getDefLockWaitTime() {
        return defLockWaitTime;
    }

    public static void setDefLockWaitTime(int defLockWaitTime) {
        IdemConfigCenter.defLockWaitTime = defLockWaitTime;
    }

    public static int getDefLockSecond() {
        return defLockSecond;
    }

    public static void setDefLockSecond(int defLockSecond) {
        IdemConfigCenter.defLockSecond = defLockSecond;
    }

    public static DynamicIdemConfigCenter getDynamicConfigCenter() {
        return dynamicConfigCenter;
    }

    public static void setDynamicConfigCenter(DynamicIdemConfigCenter dynamicConfigCenter) {
        IdemConfigCenter.dynamicConfigCenter = dynamicConfigCenter;
    }

    public static int getDefIdemTtl() {
        return defIdemTtl;
    }

    public static void setDefIdemTtl(int defIdemTtl) {
        IdemConfigCenter.defIdemTtl = defIdemTtl;
    }
}
